home *** CD-ROM | disk | FTP | other *** search
- Path: eua.ericsson.se!usenet
- From: euahjn@eua.ericsson.se (Henrik Johansson)
- Newsgroups: comp.lang.c++
- Subject: Re: Passing a pointer to a class function
- Date: 19 Jan 1996 07:08:38 GMT
- Organization: Ericsson Telecom Systems Labs, Stockholm, Sweden
- Distribution: world
- Message-ID: <4dng1m$q2u@euas20.eua.ericsson.se>
- References: <Pine.SUN.3.91.960117160141.13519A-100000@sasabe.acms.arizona.edu>
- Reply-To: euahjn@eua.ericsson.se
- NNTP-Posting-Host: euas31i2c37.eua.ericsson.se
- NNTP-Posting-User: euahjn
-
- In article <Pine.SUN.3.91.960117160141.13519A-100000@sasabe.acms.arizona.edu>, Kenton White <jwhite@sasabe.acms.arizona.edu> writes:
- >
- > I have a library subroutine that takes as an argument a pointer to a
- > function. I want to pass instead a pointer to a class function. The
- > class looks like this:
- >
- > class device {
- >
- > // ...
- >
- > public:
- >
- > //...
- > void derivs(float, complex*, complex*)
- > };
- >
- > The subroutine expects a pointer to a function like this:
- >
- > rk(void (*)(float, void*, void*))
- >
- > I pass the class function like this:
- >
- > device laser;
- > rk(void (*)(float,void*, void*))laser.derivs;
- >
- > When it compiles it gives me an anachronism warning and then crashes
- > with a memory fault on execution. I have developed a temporary fix by
- > declaring a seperate function in the main program called derivs that
- > calls the class function derivs. This works but is silly. Is there a
- > way to pass the pointer to the class function?
- >
- > Kenton
- >
-
- It is less silly to declare a static `wrapper' function inside the
- class, not in the main program;
- `static void lessSillyWrapper(float, void*, void*);'
- Then you provide it to rk by `rk(device::lessSillyWrapper)'
- Then, of course, lessSillyWrapper somehow gets the object reference to
- some `device' object and calls the `derivs' member function. See
- the FAQ section 18.
-
-